package br.srv.full.virtual.entities.menu;

import java.io.Serializable;
import java.util.List;

import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import br.srv.full.virtual.bean.base.QueryID;
import br.srv.full.virtual.entities.faces.FacesAction;
import br.srv.full.virtual.entities.faces.FacesMember;

@Entity
@DiscriminatorValue(value = "I")
@NamedQueries( {
		@NamedQuery(name = "MenuItem.findPerGroupAndRoles", query = "select mi from MenuItem mi inner join mi.roles role where mi.group = ?1 and role  in (?2) order by mi.priority"),
		@NamedQuery(name = "MenuItem.findByGroup", query = "select mi from MenuItem mi where mi.group = ?1 order by mi.priority"),
		@NamedQuery(name = "MenuItem.findByGroupAndNoRole", query = "select mi from MenuItem mi where mi.group = ?1 and mi.roles is empty order by mi.priority"),
		@NamedQuery(name = "MenuItem.findByName", query = "select mi from MenuItem mi where mi.name = ?1 order by mi.priority") })
public class MenuItem extends MenuBase implements Serializable {

	public static final QueryID FIND_PER_GROUP_AND_ROLES = new QueryID(MenuItem.class, "MenuItem.findPerGroupAndRoles");

	public static final QueryID FIND_BY_NAME = new QueryID(MenuItem.class, "MenuItem.findByName");

	public static final QueryID FIND_BY_GROUP = new QueryID(MenuItem.class, "MenuItem.findByGroup");

	public static final QueryID FIND_BY_GROUP_AND_NO_ROLES = new QueryID(MenuItem.class,
			"MenuItem.findByGroupAndNoRole");

	@ManyToOne(targetEntity = FacesMember.class, fetch = FetchType.EAGER, optional = true)
	@JoinColumn(name = "facesActionId", referencedColumnName = "id")
	@OrderBy
	private FacesAction facesAction;

	public MenuItem(String p_name) {
		setName(p_name);
		setLabel(p_name);
	}

	public MenuItem(String p_name, FacesAction l_facesAM) {
		setName(p_name);
		setLabel(p_name);
		setFacesAction(l_facesAM);
	}

	/**
	 * 
	 */
	public MenuItem() {
		super();
	}

	/**
	 * @param p_facesaction
	 */
	private void setFacesAction(FacesAction p_facesaction) {
		facesAction = p_facesaction;
	}

	public FacesAction getFacesAction() {
		return facesAction;
	}


}
